
package com.sunny.hp.common.view;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.springframework.web.servlet.view.document.AbstractExcelView;

import com.sunny.hp.common.poi.CellTypeInfo;
import com.sunny.hp.common.poi.WBStyleCellUtil;
import com.sunny.hp.common.util.LogUtil;


/********************************************************************************
 * <PRE> * 프로그램 정보 *
 * 1. Project		: BEMS2.1
 * 2. Package	: com.ncomz.nzeip.common.view
 * 3. FileName	: GenericExcelView.java
 * 4. 작성자		: P044826
 * 5. 작성일		: 2013. 11. 15. 오후 2:31:02
 * 6. 설명			:
 * </PRE>
 ********************************************************************************/

/********************************************************************************
 * <PRE> * 프로그램 정보 *
 * 1. Project		: BEMS2.1
 * 2. Package	: com.ncomz.nzeip.common.view
 * 3. FileName	: GenericExcelView.java
 * 4. 작성자		: P044826
 * 5. 작성일		: 2013. 11. 15. 오후 2:34:03
 * 6. 설명			:
 * </PRE>
 ********************************************************************************/

public abstract class  GenericExcelView  extends AbstractExcelView {

	protected Logger logger = LogUtil.getLogger(getClass());


	public Font headerFont = null;
	public Font titleFont = null;
	public Font defaultFont = null;
	public WBStyleCellUtil cellUtil = null;
	public LinkedHashMap<String, CellTypeInfo> cellMap = new LinkedHashMap<String, CellTypeInfo>();

	public Row newRow = null;
	public int newRowIndex = 2;
	public int cols = 0;


	/**
	 * <PRE> Excel Download 생성자 생성 및 Super Class
	 * 1. MethodName	: buildExcelDocument
	 * 2. ClassName		: GenericExcelView
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 11. 15. 오후 2:34:14
	 * </PRE>
	 * 		@param model
	 * 		@param wBook
	 * 		@param request
	 * 		@param response
	 * 		@throws Exception
	 */
	@Override
	protected void buildExcelDocument(Map model, HSSFWorkbook wBook, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		headerFont = wBook.createFont();
		headerFont.setFontHeightInPoints((short)13);
		headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

		titleFont = wBook.createFont();
		titleFont.setFontHeightInPoints((short)12);
		titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

		defaultFont = wBook.createFont();
		defaultFont.setFontHeightInPoints((short)12);        

		cellMap.put("header", new CellTypeInfo(XSSFCellStyle.ALIGN_CENTER,    XSSFCellStyle.VERTICAL_CENTER,headerFont, true));
		cellMap.put("body_left", new CellTypeInfo(XSSFCellStyle.ALIGN_LEFT,     XSSFCellStyle.VERTICAL_CENTER,defaultFont, false));
		cellMap.put("body_right", new CellTypeInfo(XSSFCellStyle.ALIGN_RIGHT,     XSSFCellStyle.VERTICAL_CENTER,defaultFont, false));
		cellMap.put("body_center", new CellTypeInfo(XSSFCellStyle.ALIGN_CENTER,     XSSFCellStyle.VERTICAL_CENTER,defaultFont, false));

		cellUtil = new WBStyleCellUtil(wBook, cellMap);

		ExcelDocument( model,  wBook,  request, response  ,"test1.xls");
	}
	/**********************************************************************
	 * <PRE> 엑셀 다운로드
	 * 1. MethodName	: ExcelDocument
	 * 2. ClassName		: GenericExcelView
	 * 3. 작성자			: P044826
	 * 4. 작성일			: 2013. 11. 15. 오후 2:34:07
	 * 5. 설명				:
	 * </PRE>
	 * 		@return void
	 * 		@param model
	 * 		@param wBook
	 * 		@param request
	 * 		@param response
	 * 		@throws Exception
	 **********************************************************************/
	protected abstract void ExcelDocument(Map model, HSSFWorkbook wBook, HttpServletRequest request,
			HttpServletResponse response, String templateFileName) throws Exception;

}
